#!/usr/bin/env python3

import random

class Question:
    def __init__(self, question_template, answer):
        self.question_template = question_template
        self.answer = answer

    def ask(self):
        prog = random.choice(["2 + 3 * 4", "2 + 3.5", "len('Hello, World!')", "2 ** 3", "True", "my_variable", "2 + '3'"])
        question = self.question_template.format(prog=prog)
        print(question)

        answer = input("Your answer: ")

        if answer.lower() == self.answer.lower():
            print("Correct!")
        else:
            print("Incorrect. The correct answer is:", self.answer)

# Define the questions and answers
questions = [
    Question("What is the output of the following code? {prog}", "14"),
    Question("What is the data type of the following expression? {prog}", "float"),
    Question("Which of the following is a built-in function in Python? {prog}", "len"),
    Question("What is the output of the following code? {prog}", "Hello, World!"),
    Question("What is the data type of the following expression? {prog}", "str"),
    Question("Which of the following is a valid variable name in Python? {prog}", "my_variable"),
    Question("What is the output of the following code? {prog}", "8"),
    Question("What is the data type of the following expression? {prog}", "bool"),
    Question("Which of the following is a built-in data type in Python? {prog}", "all of the above"),
    Question("What is the output of the following code? {prog}", "TypeError: unsupported operand type(s) for +: 'int' and 'tr'"),
]

# Shuffle the questions
random.shuffle(questions)

# Initialize the score
score = 0

# Loop through the questions
for question in questions:
    question.ask()

    # Increment the score if the answer is correct
    if answer.lower() == question.answer.lower():
        score += 1

# Display the final score
print("Your score is:", score, "/", len(questions))
